<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        canvas{border: 1px solid #aaa;}
    </style>
</head>
<body>
    <canvas width="600" height="400" class="myCanvas">
        当前的浏览器版本不支持，请升级浏览器
    </canvas>

    <script>
        var canvas = document.getElementsByClassName('myCanvas')[0];

        var ctx = canvas.getContext('2d');

        ctx.fillStyle = 'red';  //先设置颜色
        var left = 50;
        setInterval(function(){
            ctx.clearRect(0,0,600,400);  //清除画布，0,0代表从什么位置开始清除，600,400代表清除的宽和高
            left++;
            ctx.fillRect(left,100,50,50);  //前两个是定位，后两个是宽高
        },200);


        console.log(ctx);
    </script>
</body>
</html>
